package com.wj1c.push.receiver;

import com.wj1c.push.wechat.WeChatRequest;
import com.wj1c.push.wechat.WeChatToken;
import com.wj1c.push.wechat.request.TemplateMsgRequest;
import com.wj1c.push.wechat.response.TemplateMsgResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author: Mr.Jiao
 * @date: 2018年09月05日
 */
@Component
//@RabbitListener(queues = "information_service")
public class PushReceiver {

    private final Logger logger = LoggerFactory.getLogger(PushReceiver.class);

//    @RabbitHandler
//    @RabbitListener(queues = "information_service")       //不重复接收
    @RabbitListener(bindings=@QueueBinding(value=@Queue,exchange=@Exchange(name="fanoutExchange",type =ExchangeTypes.FANOUT)))      //重复接收
    @RabbitHandler
    public void process(String message) {
        System.out.println("收到消息2:" + message);
        //推送微信消息
//        TemplateMsgRequest request = new TemplateMsgRequest(WeChatToken.getAccesstoken());
//        request.setTouser("openid");
////        request.setTemplateId("id");
//        TemplateMsgResponse response = WeChatRequest.exec(request);
//        if(response.isOk()){
//            logger.info("push msg success,openid:{},message:{}", "openid", "message");
//        }else{
//            logger.error("push msg fail,openid:{}, message:{}", "openid", "messsage");
//        }
    }

}
